//
//  XJRegistViewController.m
//  XinJiangMall
//
//  Created by Tzyang on 2018/4/8.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJRegistViewController.h"

#import "XJRegistSetInfoViewController.h"

@interface XJRegistViewController ()<XJRegistDelegate>

@end

@implementation XJRegistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navTitle = @"注册新账号";
   // self.navButtonRight.hidden = YES;
  //  self.navButtonLeft.hidden = NO;
    
    self.xjRegistView.delegate = self;

}

- (XJRegistView *)xjRegistView{
    
    if (!_xjRegistView) {
        XJRegistView * xjRegistView = [[XJRegistView alloc]initWithFrame:CGRectMake(0, XJNaviH, KWidth, KHeight)];
        self.xjRegistView = xjRegistView;
        [self.view addSubview:self.xjRegistView];
    }
    return  _xjRegistView;
    
}
// XJRegistDelegate

#pragma mark XJRegistDelegate

- (void)nextStepAction{
    
    NSString *phone = self.xjRegistView.registPhoneTextField.text;
    NSString *code = self.xjRegistView.registCodeTextField.text;
    XJLog(@"验证码:%@--手机号:%@",code,phone);
    if (!code) {
        [MBProgressHUD showError:@"请输入验证码"];
        return;
    }
    [XJHttpTool requestVerifyCodeWithPhone:phone code:code type:@"regist" successH:^(id responseObjc) {
        NSLog(@"%@",responseObjc);
        if (![responseObjc[@"code"] isEqualToNumber:@0]) {
            [MBProgressHUD showError:responseObjc[@"message"]];
        }else{
            // 下一步
            // 在这里记录下手机号,后面用
            [XJTool xj_savePhone:phone];
            
            XJRegistSetInfoViewController * xjrSetInfoVC = [[XJRegistSetInfoViewController alloc]init];
            [self.navigationController pushViewController:xjrSetInfoVC animated:YES];
        }
    } failureH:^(NSError *error) {
        [MBProgressHUD showError:[NSString stringWithFormat:@"%@",error.localizedDescription]];

    }];
}

//- (void)viewWillAppear:(BOOL)animated{
//    [super viewWillAppear:animated];
//  //  [self.navigationController setNavigationBarHidden:NO animated:YES];
//    self.tabBarController.tabBar.hidden=YES;
//}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.view endEditing:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
